<?php

require_once 'Repository.php';
require_once 'WorkingCopy/Resource.php';

class Skjb_VersionControl_Subversion_WorkingCopy
{
    protected $repository = null;
    
    private $_checkedOut = false;
    
    protected $path = null;
    
    protected $revision = null;
    
    protected $remotePath = null;
    
    protected $remoteBase = null;
    
    protected $lastChangedDate = null;
    
    protected $lastChangedRevision = null;
    
    protected $lastChangedAuthor = null;
    
    protected $uuid = null;
    
    protected $rootDirectory = null;

    public function __construct($path)
    {
        if (!file_exists($path)) {
            throw new Exception('The given path does not exist');
        }
        
        if (!is_dir($path)) {
            throw new Exception('The given path is not a directory');
        }
        
        $this->path = realpath($path);
    }
    
    public function __get($name)
    {
        switch ($name) {
            case 'contents':
            	return $this->getRootDirectory()->contents;
            	break;
        }
        
        trigger_error('No such property "' . $name . '"');
    }
    
    public function getRootDirectory()
    {
        if ($this->rootDirectory == null) {
            $this->rootDirectory = new Skjb_VersionControl_Subversion_WorkingCopy_Resource($this->path, true, $this);
        }
        
        return $this->rootDirectory;
    }
    
    public function getRepository()
    {
        if ($this->repository == null) {
            $rootDirectory = $this->getRootDirectory();
            if ($rootDirectory->isVersionControlled()) {
                $this->repository = new Skjb_VersionControl_Subversion_Repository($rootDirectory->getRepositoryUrl());
            }
        }
        
        return $this->repository;
    }
    
    public function setRepository($repository)
    {
        if (null !== $this->getRepository()) {
            throw new Exception('The repository has already been set');
        }
        
        if (is_string($repository)) {
            $this->remotePath = $repository;
            $this->repository = new Skjb_VersionControl_Subversion_Repository($this->remotePath);
        } elseif (is_object($repository) && $repository instanceof Skjb_VersionControl_Subversion_Repository) {
            $this->repository = $repository;
        } else {
            throw new Exception('Invalid repository');
        }
        
        return $this;
    }
    
    //////////////////////////////////////////
    // Don't trust anything below this line //
    //////////////////////////////////////////
    
    public function add($files)
    {
        
    }
    
    public function blame()
    {
        
    }
    
    public function cat()
    {
        
    }
    
    public function checkout()
    {
        
    }
    
    public function cleanUp()
    {
        
    }
    
    public function commit($comment, $files = null)
    {
        
    }
    
    public function copy()
    {
        
    }
    
    public function delete($files)
    {
        
    }
    
    public function diff()
    {
        
    }
    
    public function export($path)
    {
        
    }
    
    public function import()
    {
        
    }
    
    /**
     * Gets the version control information for the given directory or file
     */
    public function info($path = '')
    {
    }
    
    public function lock()
    {
        
    }
    
    public function log()
    {
        
    }
    
    public function merge($fromPath, $fromRevision, $toPath = null, $toRevision = null)
    {
        
    }
    
    public function mkdir()
    {
        
    }
    
    public function move()
    {
        
    }
    
    public function propDel()
    {
        
    }
    
    public function propEdit()
    {
        
    }
    
    public function propGet()
    {
        
    }
    
    /**
     * Returns a list of property names for the given directory or file
     * 
     * @param string $path The directory or file
     * 
     * @return array A list of property names
     */
    public function propList($path = '')
    {
        
    }
    
    public function propSet()
    {
        
    }
    
    public function resolved($files)
    {
        
    }
    
    public function revert()
    {
        
    }
    
    public function status()
    {
        
    }
    
    public function switchPath($path, $revision = null, $depth = null)
    {
        
    }
    
    public function unlock()
    {
        
    }
    
    public function update($revision = null, $depth = null)
    {
        
    }
}